package com.zhoulz.homework.chaptor02.node;

import java.util.ArrayList;
import java.util.List;

/**
 * cmd命令操作类
 * @author zhoulz
 *
 */
public class CmdHelper {
	private static List<Client> clients = new ArrayList<Client>(10);
	private static Server server;
	
	public static void setServer(Server server) {
		CmdHelper.server = server;
	}
	
	/**
	 * 添加client
	 * @param client
	 */
	public static void addClient(Client client){
		clients.add(client);
	}
	
	/**
	 * 停止发送文件
	 * @param nodeName
	 */
	public static void stopSendFile(String nodeName){
		for (Client client : clients) {
			if(client.getToNodeName().equals(nodeName)){
				client.shutdown();
			}
		}
	}
	
	/**
	 * 节点关闭
	 */
	public static void shutdown(){
		// 停止发送数据文件,停止所有client端
		for (Client client : clients) {
			client.shutdown();
		}
		// 停止server端
		server.shutdown();
	}
}
